﻿
@{
    ///商品列表
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Wares</title>

    <link href="~/Content/BootStrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/BootStrap/css/bootstrap-theme.min.css" rel="stylesheet" />
    <link href="~/Content/BootStrap/css/docs.min.css" rel="stylesheet" />
    <link href="~/bootstrapvalidator-master/dist/css/bootstrapValidator.min.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/BootStrap/js/bootstrap.min.js"></script>
    <script src="~/Content/BootStrap/js/docs.min.js"></script>
    <script src="~/bootstrapvalidator-master/dist/js/bootstrapValidator.min.js"></script>
    <script src="~/bootstrapvalidator-master/dist/js/language/zh_CN.js"></script>
</head>
<body>
    <div class="form-inline" style="margin-top:10px;">
        <div class="form-group">
            <a href="AddWares" class="btn btn-primary">添加商品</a>
        </div>
        <div class="form-group">
            <label class="control-label" for="CID">按类别查看</label>
            <select class="form-control" name="CID" id="CID">
                <option value="0" selected="selected">请选择类别</option>
                @{IList<Shop.Wares.Models.WaresCategory> wcinfo = ViewBag.wcinfo;}
                @foreach (var item in wcinfo)
                {
                    <option value="@item.CID">@item.CName</option>
                }
            </select>
        </div>
        <div class="form-group">
            <label class="control-label" for="SCID">子类别</label>
            <select class="form-control" name="SCID" id="SCID">
                <option value="0" selected="selected">请选择类别</option>
            </select>
        </div>
        <div class="form-group">
            <input type="text" class="form-control" id="WName" name="WName" placeholder="输入商品名">
            <input type="button" class="btn btn-primary" value="搜索" id="serch" name="serch"/>
        </div>
        <div class="form-group">
            <label class="control-label" for="Status">商品状态</label>
            <select class="form-control" name="Status" id="Status">
                <option value="0" selected="selected">已上架</option>
                <option value="1">已下架</option>
            </select>
        </div>
    </div>
    <div id="main" style="margin-top:10px;">
        @Html.Action("_WaresSearch", "Wares")
    </div>
    <script type="text/javascript">
        function UpFrame(WID)
        {
            var gnl = confirm("确定要上架吗?");
            if (gnl == true) {
                $.ajax({
                    url: '@Url.Action("UpFrame", "Wares")',
                    type: 'post',
                    dataType: 'text',
                    data: { WID: WID },
                    success: function (data) {
                        if (data == "NO") {
                            alert("上架失败");
                        }
                        else {
                            alert("上架成功");
                            //window.location.reload();
                            WaresSearch();
                        }
                    }
                });
            }
        } 
        function DownFrame(WID) {
            var gnl = confirm("确定要下架吗?");
            if (gnl == true) {
                $.ajax({
                    url: '@Url.Action("DownFrame", "Wares")',
                    type: 'post',
                    dataType: 'text',
                    data: { WID: WID },
                    success: function (data) {
                        if (data == "NO") {
                            alert("下架失败");
                        }
                        else {
                            alert("下架成功");
                            //window.location.reload();
                            WaresSearch();
                        }
                    }
                });
            }
        }
        //商品置顶
        function stick(WID)
        {
            var gnl = confirm("确定要置顶吗?");
            if (gnl == true) {
                $.ajax({
                    url: '@Url.Action("OrderTimeWares", "Wares")',
                    type: 'post',
                    dataType: 'text',
                    data: { WID: WID },
                    success: function (data) {
                        if (data == "NO") {
                            alert("置顶失败");
                        }
                        else
                        {
                            alert("置顶成功");
                            //window.location.reload();
                            WaresSearch();
                        }
                    }
                });
            }
        }
        //删除商品
        function del(WID)
        {
            var gnl = confirm("确定要删除吗?");
            if (gnl == true) {
                $.ajax({
                    url: '@Url.Action("DelWares", "Wares")',
                    type: 'post',
                    dataType: 'text',
                    data: { WID: WID },
                    success: function (data) {
                        if (data == "NO") {
                            alert("删除失败");
                        }
                        else
                        {
                            alert("删除成功");
                            @*location.href = "@(Url.Action("Wares", "Wares", new { Page = 1 }))";*@
                            WaresSearch();
                        }
                    }
                });
            }
        }
        //当选择类别时动态加载子类别内容
        $("#CID").change(function () {
            var select = $(this).val();
            $("#SCID").empty();
            $("#SCID").append(" <option value='0' selected='selected'>请选择类别</option>")
            if (select > 0)
            {
                 $.ajax({
                    url: '@Url.Action("Getswinfo", "Wares")',
                    type: 'post',
                    dataType: 'json',
                    data: { CID: select },
                    success: function (data) {
                        if (data != null) {
                            $.each(data, function (i, item) {
                                $("#SCID").append("<option value='" + item.SCID + "'>" + item.SCName + "</option>");   //为Select追加一个Option(下拉项)
                            });
                        }
                    }
                });
            }
            WaresSearch();

        });
        //当选择子类别时动态加载子类别内容
        $("#SCID").change(function () {
            var select = $(this).val();
            if (select > 0)
            {
                 $.ajax({
                    url: '@Url.Action("Getswinfo", "Wares")',
                    type: 'post',
                    dataType: 'json',
                    data: { CID: select },
                    success: function (data) {
                        if (data != null) {
                            $.each(data, function (i, item) {
                                $("#SCID").append("<option value='" + item.SCID + "'>" + item.SCName + "</option>");   //为Select追加一个Option(下拉项)
                            });
                        }
                    }
                });
            }
            WaresSearch();

        });
        //搜索
        $("#serch").click(function () {
            var WName = $("#WName").val();
            if (WName == "")
            {
                alert("商品名不能为空");
            }
            else
            {
                WaresSearch();
            }
        });
        //商品状态
        $("#Status").change(function () {
            WaresSearch();
        });
        //ajax加载查询的结果
        function WaresSearch()
        {
             $.ajax({
                url: '@Url.Action("_WaresSearch", "Wares")',
                type: 'post',
                data: { CID: $("#CID").val(), Page: 1, SCID: $("#SCID").val(), WName: $("#WName").val(), Status: $("#Status").val() },
                dataType: 'text',
                success: function (data) {
                    $("#main").html(data);
                }
            });
        }
    </script>
</body>
</html>
